package what.basic.swingcommon;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class swingmodality {
	private static Frame f1;
	private static Dialog d11;
	private static Dialog d12;
	private static Frame f2;
	private static Dialog d21;
	private static Dialog d ;
	private static Frame f3;
	private static Frame f4;
	private static FileDialog fd4;
	private static WindowListener closewindow=new WindowAdapter(){
		public void windowClosing(WindowEvent e){
			e.getWindow().dispose();
		}
	};
	public static void main(String[] args) {
		GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
		GraphicsDevice gd=ge.getDefaultScreenDevice();
		GraphicsConfiguration gc=gd.getDefaultConfiguration();
		int sw=gc.getBounds().width-64;
		int sh=gc.getBounds().height-64;
		Label l;
		Button b;
		MenuBar mb;
		Menu m;
		MenuItem mi;
		Font labelfont=new Font("Tahoma",24,Font.PLAIN);
		f1=new Frame("Parent frame");
		f1.setBounds(32, 32, 300, 200);
		f1.addWindowListener(closewindow);
		mb=new MenuBar();
		m=new Menu("Test");
		mi=new MenuItem("Show modeless");
		mi.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				d11.setVisible(true);
			}
		});
		m.add(mi);
		mb.add(m);
		f1.setMenuBar(mb);
		f1.setLayout(new BorderLayout());
		l=new Label("Frame");
		l.setAlignment(Label.CENTER);
		l.setFont(labelfont);
		l.setBackground(Color.RED);
		f1.add(l,BorderLayout.CENTER);
		f1.setVisible(true);
		d11=new Dialog(f1,"Modeless Dialog");
		d11.setBounds(132,132,300,200);
		d11.addWindowListener(closewindow);
		d11.setLayout(new BorderLayout());
		l=new Label("Modeless");
		l.setAlignment(Label.CENTER);
		l.setFont(labelfont);
		l.setBackground(Color.RED);
		d11.add(l,BorderLayout.CENTER);
		b=new Button("Show Document-modal");
		b.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent arg0) {
				d12.setVisible(true);
			}
		});
		d11.add(b,BorderLayout.SOUTH);
		d12=new Dialog((Window)d11,"Document-modal Dialog",Dialog.ModalityType.DOCUMENT_MODAL);
		d12.setBounds(232,232,300,200);
		d12.addWindowListener(closewindow);
		d12.setLayout(new BorderLayout());
		l=new Label("DOCMENT-MODAL");
		l.setAlignment(Label.CENTER);
		l.setFont(labelfont);
		l.setBackground(Color.red);
		d12.add(l,BorderLayout.CENTER);
		f2=new Frame("Parent Frame");
		f2.setBounds(sw-300+32,32,300,200);
		f2.addWindowListener(closewindow);
		mb=new MenuBar();
		m=new Menu("test");
		mi=new MenuItem("ShowMODELESS");
		mi.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				d21.setVisible(true);
			}
			
		});
		m.add(mi);
		mb.add(m);
		f2.setMenuBar(mb);
		f2.setLayout(new BorderLayout());
		l=new Label("Frame");
		l.setAlignment(Label.CENTER);
		l.setFont(labelfont);
		f2.add(l,BorderLayout.CENTER);
		f2.setVisible(true);
		d21=new Dialog(f2,"Modeless dialog");
		d21.setBounds(sw-400+32,132,300,200);
		d21.addWindowListener(closewindow);
		d21.setLayout(new BorderLayout());
		l=new Label("MODELESS");
		l.setBackground(Color.blue);
		d21.add(l,BorderLayout.CENTER);
		b=new Button("Show document-modal");
		b.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				d .setVisible(true);
			}
		});
		d21.add(b,BorderLayout.SOUTH);
		d =new Dialog((Window)d21,"dOCUMENT-MODAL DIALOG",Dialog.ModalityType.DOCUMENT_MODAL);
		d .addWindowListener(closewindow);
	}

}
